<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the name of the token.</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="phptoken.construct.html">« PhpToken::__construct</a></li>
      <li style="float: right;"><a href="phptoken.is.html">PhpToken::is »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.phptoken.html">PhpToken</a></li>
    <li>Returns the name of the token.</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="phptoken.gettokenname" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PhpToken::getTokenName</h1>
  <p class="verinfo">(PHP 8)</p><p class="refpurpose"><span class="refname">PhpToken::getTokenName</span> &mdash; <span class="dc-title">Returns the name of the token.</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-phptoken.gettokenname-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PhpToken::getTokenName</strong></span>(): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>

  <p class="para rdfs-comment">
   Returns the name of the token.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-phptoken.gettokenname-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-phptoken.gettokenname-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An ASCII character for single-char tokens,
   or one of T_* constant names for known tokens (see <a href="tokens.html" class="xref">解析器记号（token）列表</a>),
   or <strong><code>null</code></strong> for unknown tokens.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-phptoken.gettokenname-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-3825">
   <p><strong>示例 #1 <span class="function"><strong>PhpToken::getTokenName()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;known&nbsp;token<br /></span><span style="color: #0000BB">$token&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">(</span><span style="color: #0000BB">T_ECHO</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'echo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTokenName</span><span style="color: #007700">());&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;string(6)&nbsp;"T_ECHO"<br /><br />//&nbsp;single-char&nbsp;token<br /></span><span style="color: #0000BB">$token&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">(</span><span style="color: #0000BB">ord</span><span style="color: #007700">(</span><span style="color: #DD0000">';'</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">';'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTokenName</span><span style="color: #007700">());&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;string(1)&nbsp;";"<br /><br />//&nbsp;unknown&nbsp;token<br /></span><span style="color: #0000BB">$token&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PhpToken</span><span style="color: #007700">(</span><span style="color: #0000BB">10000&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\0"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$token</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTokenName</span><span style="color: #007700">());&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;-&gt;&nbsp;NULL</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-phptoken.gettokenname-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="phptoken.tokenize.html" class="function" rel="rdfs-seeAlso">PhpToken::tokenize()</a> - Splits given source into PHP tokens, represented by PhpToken objects.</span></li>
   <li class="member"><span class="function"><a href="function.token-name.html" class="function" rel="rdfs-seeAlso">token_name()</a> - 获取提供的 PHP 解析器代号的符号名称</span></li>
  </ul>
 </div>

</div></div></div></body></html>